package com.ewanghuiju.app.ui.watermail.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.component.ImageLoader;
import com.ewanghuiju.app.model.bean.response.WaterOrderListResponBean;
import com.ewanghuiju.app.ui.web.MyWebviewActivity;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.makeramen.roundedimageview.RoundedImageView;
import com.muddzdev.styleabletoast.StyleableToast;
import com.stx.xhb.androidx.OnDoubleClickListener;

/**
 * @author sj  qq:751943509
 * @class 积分订单列表 adapter
 * @time 2020/2/20
 */
public class WaterOrderListAdapter extends BaseQuickAdapter<WaterOrderListResponBean, BaseViewHolder> {

    public WaterOrderListAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    protected void convert(BaseViewHolder helper, WaterOrderListResponBean item) {
        ImageView riv_head = helper.getView(R.id.iv_head);
        riv_head.setBackgroundResource(R.mipmap.ic_order_logo);
//       ImageLoader.load(mContext,item.getHead(),riv_head);
        RoundedImageView iv_shop_img = helper.getView(R.id.iv_shop_img);
        ImageLoader.load(mContext, item.getGoods_img(), iv_shop_img);

        helper.setText(R.id.tv_title, TextUtils.isEmpty(item.getGoods_title()) ? "" : item.getGoods_title());
        helper.setText(R.id.tv_shopname, TextUtils.isEmpty(item.getCreate_time()) ? "" : item.getCreate_time());
        helper.setText(R.id.tv_price, TextUtils.isEmpty(item.getPay_price()) ? "" : item.getPay_price());
        TextView mTvPintuanStatus = helper.getView(R.id.tv_pintuan_status);
        TextView tvFukuan = helper.getView(R.id.tv_fukuan);
        //查看物流
        TextView tvLlookwl = helper.getView(R.id.tv_look_wl);
        tvLlookwl.setVisibility(View.GONE);
        mTvPintuanStatus.setText("兑换成功");
        if (item.getStatus() == 1) {
            tvFukuan.setText("待发货");
        } else if (item.getStatus() == 2) {
            tvFukuan.setText("已发货");
        } else if (item.getStatus() == 3) {
            tvFukuan.setText("已完成");
            tvLlookwl.setVisibility(View.VISIBLE);
            tvLlookwl.setOnClickListener(new OnDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    if (TextUtils.isEmpty(item.getCourier_link())) {
                        StyleableToast.makeText(mContext, "未查询到信息", Toast.LENGTH_SHORT, R.style.mytoast).show();
                        return;
                    }
                    new StartActivityUtil(mContext, MyWebviewActivity.class).putExtra("url", item.getCourier_link())
                            .putExtra(Constants.WEBURL_TITLE, Constants.WEBURL_KUAIDI_TITLE).startActivity(true);
                }
            });
        }
        //客服
        helper.getView(R.id.tv_kf).setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                new StartActivityUtil(mContext, MyWebviewActivity.class).putExtra("url", Constants.WEBURL_KEFU)
                        .putExtra(Constants.WEBURL_TITLE, Constants.WEBURL_KEFU_TITLE).startActivity(true);
            }
        });
    }
}
